﻿using Inventory.API.Application.Command.WarehouseManagementCommand;
using Inventory.API.DTO.WarehousemanagementDTO;
using Inventory.Domain;
using Inventory.Errorcode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Inventory.API.Controllers
{
    /// <summary>
    /// 仓储管理控制器 
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WarehousingController : ControllerBase
    {

        private readonly IMediator _mediator;
        /// <summary>
        /// 仓储管理控制器构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public WarehousingController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 新增仓储
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> AddWarehousing(AddWarehousingCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 显示仓储列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> GetWarehousingList([FromQuery] GetWarehousingListQueryCommand command)
        {
            return await _mediator.Send(command);
        }


        /// <summary>
        /// 删除仓储
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult> DeleteWarehousing([FromQuery] DeleteWarehousingCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 显示仓储详情
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<Warehousemanagement>> GetWarehousingInfo([FromQuery] GetWarehousingInfoCommand query)
        {
            return await _mediator.Send(query);
        }
        /// <summary>
        /// 更新仓储
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult> UpdateWarehousing(UpdateWarehousingCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 显示仓储所有信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<IList<WarehousemanagementDTOS>>> GetAllWarehousingList([FromQuery] GetAllWarehousingListQueryCommand command)
        {
            return await _mediator.Send(command);


        }

    }
}
